const initialState = { userInfo: {}, availableSpace: 0 };
const loginReducer = (state = initialState, action) => {
  if (action.type === "login") {
    return { userInfo: JSON.parse(localStorage.getItem("userInfo")) };
  }
  if (action.type === "logout") {
    localStorage.removeItem("userInfo");
    localStorage.removeItem("availableSpace");
    return {};
  }
  if (action.type === "refreshAvailableSpace") {
    return {
      userInfo: JSON.parse(localStorage.getItem("userInfo")),
      availableSpace: JSON.parse(localStorage.getItem("availableSpace")),
    };
  }
  return state;
};
export default loginReducer;
